<?php
/**
 * util guid
 * @package common_lib_util
 */
/**
 * util guid
 * @author pandajingjing
 * @package common_lib_util
 */
class util_guid{

	/**
	 * 获取GUID
	 * @return string
	 */
	static function getGuid(){
		$strRaw=strtoupper(md5(strtolower(get_config('server_name').'/'.sys_variable::getInstance()->getParam('SERVER_ADDR','server')).':'.self::_getTimeMillis().':'.self::_getLong()));
		return substr($strRaw,0,8).'-'.substr($strRaw,8,4).'-'.substr($strRaw,12,4).'-'.substr($strRaw,16,4).'-'.substr($strRaw,20);
	}

	/**
	 * 获取时间参数
	 * @return string
	 */
	private static function _getTimeMillis(){
		list($usec,$sec)=explode(' ',microtime());
		return $sec.substr($usec,2,3);
	}

	/**
	 * 获取整长型数
	 * @return long
	 */
	private static function _getLong(){
		$tmp=rand(0,1)?'-':'';
		return $tmp.rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(100,999).rand(100,999);
	}
}